package com.slg.android.manyanime.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.slg.android.manyanime.R;
import com.slg.android.manyanime.bean.NoticeList;
import com.slg.android.manyanime.utils.DataStore;

import java.util.List;

/**
 * Created by Darker on 2015/3/12.
 */
public class NoticeListAdapter extends BaseAdapter{
    private LayoutInflater inflater;
    private List<NoticeList> data;
    public NoticeListAdapter(Context context, List<NoticeList> data) {
        if(context != null){
            inflater = LayoutInflater.from(context);
        }
        this.data = data;

    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View ret = null;
        if(convertView != null){
            ret = convertView;
        }else{
            ret = inflater.inflate(R.layout.item_my_notice_list,parent,false);
        }

        ViewHolder holder = (ViewHolder) ret.getTag();
        if(holder == null){
            holder = new ViewHolder();
            holder.image = (ImageView)ret.findViewById(R.id.item_my_notify_title_img);
            holder.time = (TextView)ret.findViewById(R.id.item_my_notify_time_txt);
            holder.content = (TextView)ret.findViewById(R.id.item_my_notify_content_text);
            ret.setTag(holder);
        }
        NoticeList noticeList = data.get(position);
        holder.content.setText(noticeList.getCont());
        holder.time.setText(noticeList.getUpdate_time());

        BitmapUtils bitmapUtils = DataStore.getBitmapUtils();
        bitmapUtils.configDefaultLoadingImage(R.drawable.item_default);
        bitmapUtils.display(holder.image,noticeList.getIcon());

        return ret;
    }


    public static class ViewHolder{
        public ImageView image;
        public TextView time;
        public TextView content;
    }

}
